//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ObjectBuilder;
using EntLibContrib.Mapping.Mappers;

namespace EntLibContrib.Mapping.Configuration
{
	/// <summary>
	/// Configuration data defining SuperMapperData. This configuration section adds the element
	/// </summary>    
	[Assembler(typeof(SuperMapperAssembler))]
	public class SuperMapperData : MapperData
	{
		#region Constants
		private const string domainObjectSuperTypeColumnProperty = "domainObjectSuperTypeColumn";
		private const string domainObjectSuperTypeNamesProperty = "superTypes";
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the table column that holds the domain object super type data values.
		/// </summary>
		/// <value>The column that holds the domain object super type data values.</value>
		[ConfigurationProperty(domainObjectSuperTypeColumnProperty, IsRequired = true)]
		public string DomainObjectSuperTypeColumn
		{
			get { return (string)base[domainObjectSuperTypeColumnProperty]; }
			set { base[domainObjectSuperTypeColumnProperty] = value; }
		}

		/// <summary>
		/// Gets the collection of data value/super type associations for the mapper.
		/// </summary>
		/// <remarks>if this collection is empty it will be assumed that the data column contains
		/// properly formatted type information, otherwise this list maps data values found in
		/// the data transfer object with proper formatted type information</remarks>
		[ConfigurationProperty(domainObjectSuperTypeNamesProperty)]
		public NamedElementCollection<SuperTypeData> DomainObjectSuperTypes
		{
			get { return (NamedElementCollection<SuperTypeData>)this[domainObjectSuperTypeNamesProperty]; }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initializes a new instance of the <see cref="SuperMapperData"/> class.
		/// </summary>
		public SuperMapperData ()
		{
			InitializeDomainObjectSuperTypes();
		}

		/// <summary>
		/// Initialize a new instance of the <see cref="SuperMapperData"/> class.
		/// </summary>
		/// <param name="name">The name of the <see cref="SuperMapperData"/>.</param>
		/// <param name="tableName">The data transfer object table name.</param>
		/// <param name="domainObjectSuperTypeColumn">The domain object super type column.</param>
		public SuperMapperData(string name, string tableName, string domainObjectSuperTypeColumn)
			: base(name, tableName, typeof(SuperMapper))
		{
			this.DomainObjectSuperTypeColumn = domainObjectSuperTypeColumn;
			InitializeDomainObjectSuperTypes();
		}
		#endregion

		#region Private Methods
		private void InitializeDomainObjectSuperTypes()
		{
			base[domainObjectSuperTypeNamesProperty] = new NamedElementCollection<SuperTypeData>();
		}
		#endregion
	}
}